package com.xingchi.tornado.dict.controller;

import com.xingchi.tornado.basic.Result;
import com.xingchi.tornado.dict.model.dto.DictItemAddDTO;
import com.xingchi.tornado.dict.model.dto.DictItemDTO;
import com.xingchi.tornado.dict.model.dto.DictItemEditDTO;
import com.xingchi.tornado.dict.model.dto.DictItemQueryDTO;
import com.xingchi.tornado.dict.service.DictItemService;
import com.xingchi.tornado.model.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *  字典项前端控制器
 *
 * @author xingchi
 * @date 2025-05-27 15:24
 */
@RestController
@RequestMapping("/dict/dict-item")
@RequiredArgsConstructor
@Tag(name = "字典项", description = "字典项操作")
public class DictItemController {

    private final DictItemService dictItemService;

    @PostMapping
    @Operation(summary = "添加字典项", description = "添加字典项")
    public Result<Long> addItem(@RequestBody @Validated DictItemAddDTO dictItem) {
        return Result.ok(dictItemService.addItem(dictItem));
    }

    @PutMapping
    @Operation(summary = "修改字典项", description = "修改字典项")
    public Result<Boolean> updateItem(@RequestBody @Validated DictItemEditDTO dictItem) {
        return Result.ok(dictItemService.updateItem(dictItem));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除字典项", description = "删除字典项")
    public Result<Boolean> deleteItem(@PathVariable Long id) {
        return Result.ok(dictItemService.deleteItem(id));
    }

    @GetMapping("/pageList")
    @Operation(summary = "分页查询字典项", description = "分页查询字典项")
    public Result<PageResult<DictItemDTO>> pageList(DictItemQueryDTO query) {
        return Result.ok(dictItemService.selectPageByQuery(query));
    }

    @GetMapping("/list")
    @Operation(summary = "查询字典项", description = "查询字典项")
    public Result<List<DictItemDTO>> list(DictItemQueryDTO query) {
        return Result.ok(dictItemService.selectByQuery(query));
    }

}
